public class Test {
    public static void main(String[] args) {
        HashBucket hashBucket = new HashBucket();
        hashBucket.put(1,11);
        hashBucket.put(2,22);
        hashBucket.put(12,12);
        hashBucket.put(22,22);
        hashBucket.put(13,13);
        hashBucket.put(3,33);
        System.out.println(hashBucket.get(3));
    }
}
class Solution {
    class compare implements Comparator<Map.Entry<String,Integer>> {
        public int compare(Map.Entry<String,Integer> o1,Map.Entry<String,Integer> o2) {
            if(o1.getValue().compareTo(o2.getValue()) == 0) {
                return o2.getKey().compareTo(o1.getKey());
            }
            return o1.getValue().compareTo(o2.getValue());
        }
    }
    public List<String> topKFrequent(String[] words, int k) {
        HashMap<String,Integer> map = new HashMap<>();
        for(int i=0;i<words.length;i++) {
            if(map.get(words[i]) == null) {
                map.put(words[i],1);
            }else {
                int val = map.get(words[i]);
                val++;
                map.put(words[i],val);
            }
        }

        PriorityQueue<Map.Entry<String,Integer>> queue = new PriorityQueue<>(new Comparator<Map.Entry<String, Integer>>() {
            @Override
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                if(o1.getValue().compareTo(o2.getValue()) == 0) {
                    return o2.getKey().compareTo(o1.getKey());
                }
                return o1.getValue().compareTo(o2.getValue());
            }
        });
        for(Map.Entry<String,Integer> e:map.entrySet())  {
            if(queue.size() < k) {
                queue.offer(e);
            }else{
                if(queue.peek().getValue() < e.getValue()) {
                    queue.poll();
                    queue.offer(e);
                }else if (queue.peek().getValue() == e.getValue()){
                    if(queue.peek().getKey().compareTo(e.getKey()) > 0) {
                        queue.poll();
                        queue.offer(e);
                    }
                }
            }
        }
        List<String> list = new ArrayList<>();
        for(int i=0;i<k;i++) {
            Map.Entry<String,Integer> tmp = queue.poll();
            list.add(tmp.getKey());
        }
        Collections.reverse(list);
        return list;
    }
}